package com.perye.dokit.workcontroller;

import com.perye.dokit.aop.log.Log;
import com.perye.dokit.base.BaseController;
import com.perye.dokit.newservice.BaseService;
import com.perye.dokit.newservice.HqWeddingTypesService;
import com.perye.dokit.newservice.PersionService;
import com.perye.dokit.newservice.WeddingDataService;
import com.perye.dokit.utils.DateUtils;
import com.perye.dokit.utils.pageData.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: chenhao
 * \* Date: 2021/7/19
 * \* Time: 11:13
 * \* Description: 基础信息模块
 * \
 */

@RestController
@RequestMapping("/api/weixin")
public class WeixinAppController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(WeixinAppController.class);
    @Autowired
    private HqWeddingTypesService service;
    @Autowired
    private WeddingDataService weddingDataService;
    @Autowired
    private BaseService baseService;
    @Autowired
    private PersionService PersionService;
    @PostMapping("/getBase")
    public ResponseEntity<Object> getBase(@RequestBody PageData pageData) throws Exception {
        PageData result = new PageData();
        try {

            List<PageData> list = baseService.getListBase(pageData);
            result.put("content", list);
            result.put("status", 0);
            result.put("msg", "查询成功");
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception(e.getMessage());
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @PostMapping("/getWeddingTypes")
    public ResponseEntity<Object> getWeddingTypes(@RequestBody PageData pageData) throws Exception {
        PageData result = new PageData();
        try {
            List<PageData> list = service.getList(pageData);
            result.put("content", list);
            result.put("status", 0);
            result.put("msg", "查询成功");
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception(e.getMessage());
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @PostMapping("/getWeddings")
    public ResponseEntity<Object> getWeddings(@RequestBody(required=false) PageData pageData) throws Exception {
        PageData result = new PageData();
        try {
            List<PageData> list = weddingDataService.getList(pageData);
            result.put("content", list);
            result.put("status", 0);
            result.put("msg", "查询成功");
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception(e.getMessage());
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
    @PostMapping("/getPersion")
    public ResponseEntity<Object> getPersion(@RequestBody PageData pageData) throws Exception {
        PageData result = new PageData();
        try {
            List<PageData> list = PersionService.getList(pageData);
            result.put("content", list);
            result.put("status", 0);
            result.put("msg", "查询成功");
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception(e.getMessage());
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}